﻿using System;
using System.Collections.Generic;
using System.Text;
using ExpressionUtil.Node.Common;
using System.Diagnostics;
using System.Runtime.Serialization;

namespace ExpressionUtil.Node
{
    /// <summary>
    /// 布尔类型字面量节点
    /// </summary>
    [Serializable]
    internal class ConstBoolNode : Common.Node, ISerializable
    {
        /// <summary>
        /// 解析的值
        /// </summary>
        private bool data;

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ConstBoolNode()
            : this(false)
        {
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="number">解析的数字</param>
        public ConstBoolNode(bool param)
        {
            this.data = param;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="info">要填充数据的 System.Runtime.Serialization.SerializationInfo</param>
        /// <param name="context">此序列化的目标</param>
        public ConstBoolNode(SerializationInfo info, StreamingContext context)
            : base()
        {
            this.data = info.GetBoolean("data");
        }

        /// <summary>
        /// 获取或设置解析的值
        /// </summary>
        public bool Data
        {
            get
            {
                return this.data;
            }
            set
            {
                this.data = value;
            }
        }

        /// <summary>
        /// 执行节点运算
        /// </summary>
        /// <param name="context">执行参数</param>
        /// <returns>执行结果的类型</returns>
        public override ExecuteRunTimeType Execute(ExecuteContext context)
        {
            context.GlobalTempBool = this.data;
            return ExecuteRunTimeType.Bool;
        }

#if DEBUG
        protected override void DumpCore()
        {
            Debug.WriteLine("ConstBoolNode,value:" + this.data.ToString());
        }
#endif

        #region ISerializable 成员
        /// <summary>
        /// 获取对象数据
        /// </summary>
        /// <param name="info">要填充数据的 System.Runtime.Serialization.SerializationInfo</param>
        /// <param name="context">此序列化的目标</param>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("data", this.data);
        }

        #endregion
    }
}
